package com.peaksport.framework.extend.redis;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import com.peaksport.framework.util.PKDevUtils;
import com.peaksport.framework.util.PKPublicUtils;

@Component
public class PKRedisTemplate {
	

	@SuppressWarnings("rawtypes")
	@Autowired
	private RedisTemplate redisTemplate;
	
	@Value("${peak.pkms.isTest:false}")
	private boolean isTest;
	
	/** 公司名*/
	@Value("${peak.redis.prefix.company}")
	private String prefix_company;
	/** 系统名*/
	@Value("${peak.redis.prefix.system}")
	private String prefix_system;
	/** 项目名*/
	@Value("${peak.redis.prefix.project}")
	private String prefix_project;
	/** 微服务名称 */
	@Value("${service_description.name}")
	private String serviceName;
	/**  模块名 */
	@Value("${peak.redis.prefix.module}")
	private String prefix_module;
	/** 默认缓存时间,默认为5分钟 */
	@Value("${peak.redis.defaultExpireTime:300}")
	private long defaultExpireTime;

	
	@SuppressWarnings("unchecked")
	@PostConstruct
	private void init() {
		RedisSerializer<String> stringSerializer = new StringRedisSerializer();
		GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer();
		
		redisTemplate.setKeySerializer(stringSerializer);
		redisTemplate.setHashKeySerializer(stringSerializer);
		redisTemplate.setValueSerializer(jsonSerializer);
		redisTemplate.setHashValueSerializer(jsonSerializer);
	}
	
	
	/**
	 * 获取缓存key的全名称
	 * 
	 * @param prefix_cmp 公司
	 * @param prefix_sys 系统
	 * @param prefix_proj 项目
	 * @param prefix_module 模块
	 * @param key
	 * @return
	 */
	private String getFullKey(String prefix_cmp, String prefix_sys,String prefix_proj, String prefix_module, String key) {
		PKDevUtils.verifyDevNull(prefix_cmp, "prefix_cmp不能为空");
		PKDevUtils.verifyDevNull(prefix_sys, "prefix_sys不能为空");
		StringBuffer str = new StringBuffer();
		if (isTest) str.append("TEST:");
		str.append(prefix_cmp).append(PKPublicUtils.COLON)
		.append(prefix_sys).append(PKPublicUtils.COLON);
		if (!PKPublicUtils.isEmpty(prefix_proj))
			str.append(prefix_proj).append(PKPublicUtils.COLON);
		if (!PKPublicUtils.isEmpty(prefix_module))
			str.append(prefix_module).append(PKPublicUtils.COLON);
		str.append(key);
		return str.toString();
	}
	/**
	 * 获取缓存key的全名称,前缀自动加入peak.redis前缀配置项"company","system”
	 * 
	 * @param prefix_proj 项目
	 * @param prefix_module 模块
	 * @param key
	 * @return
	 */
	public String getFullKey(String prefix_proj, String prefix_module, String key) {
		PKDevUtils.verifyDevNull(prefix_company, "需配置redis缓存前缀项[peak.redis.prefix.company]");
		PKDevUtils.verifyDevNull(prefix_system, "需配置redis缓存前缀项[peak.redis.prefix.system]");
		return getFullKey(prefix_company,prefix_system,prefix_proj,prefix_module,key);
	}
	/**
	 * 获取缓存key的全名称,前缀自动加入peak.redis前缀配置项"company","system”,"project"
	 * 如果"project"未配置,则用serviceName服务名替代
	 * 
	 * @param prefix_module 模块
	 * @param key
	 * @return
	 */
	public String getFullKey(String prefix_module, String key) {
		PKDevUtils.verifyDevNull(prefix_company, "需配置redis缓存前缀项[peak.redis.prefix.company]");
		PKDevUtils.verifyDevNull(prefix_system, "需配置redis缓存前缀项[peak.redis.prefix.system]");
		return getFullKey(prefix_company,prefix_system,PKPublicUtils.isEmpty(prefix_project) ? serviceName : prefix_project,prefix_module,key);
	}
	/**
	 * 获取缓存key的全名称,前缀自动加入peak.redis前缀配置项"company","system”,"project","module"
	 * 如果"project"未配置,则用serviceName服务名替代
	 * @param key
	 * @return
	 */
	public String getFullKey(String key) {
		return getFullKey(prefix_module,key);
	}
	
	/**
	 * 自定义redis缓存key
	 * 
	 * @param prefix 前缀
	 * @param key 
	 * @return
	 */
	public String getCustomKey(String prefixKey, String key) {
		StringBuffer str = new StringBuffer();
		if (isTest) str.append("Test:");
		if (!PKPublicUtils.isEmpty(prefixKey)) str.append(prefixKey).append(PKPublicUtils.COLON);
		str.append(key);
		return str.toString();
	}
	
	/**
	 * 设置字符型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * 
	 * @param key redis缓存key
	 * @param value
	 */
	public void setString(String key, String value) {
		String newKey = getFullKey(key);
		_setString(newKey,value,defaultExpireTime);
	}
	
	/**
	 * 设置字符型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 
	 * @param key redis缓存key
	 * @param value
	 * @param expireTime 缓存有效期(秒)
	 */
	public void setString(String key, String value, long expireTime) {
		String newKey = getFullKey(key);
		_setString(newKey,value,expireTime);
	}
	
	/**
	 * 设置字符型缓存,不补齐key前缀项目
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * 
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @param value
	 */
	public void setString(String prefixKey, String key, String value) {
		String newKey = getCustomKey(prefixKey, key);
		_setString(newKey,value,defaultExpireTime);
	}
	
	/**
	 * 设置字符型缓存,不补齐key前缀项目
	 * 
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @param value
	 * @param expireTime 缓存有效期(秒)
	 */
	public void setString(String prefixKey, String key, String value, long expireTime) {
		String newKey = getCustomKey(prefixKey, key);
		_setString(newKey, value,expireTime);
	}

	/**
	 * 设置字符型缓存
	 * 
	 * @param key redis缓存key
	 * @param value
	 * @param expireTime 缓存有效期(秒)
	 */
	@SuppressWarnings("unchecked")
	private void _setString(String key, String value,  long expireTime) {
		redisTemplate.opsForValue().set(key, value,expireTime, TimeUnit.SECONDS);
	}
	
	
	/**
	 * 获取字符型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 
	 * @param key redis缓存key
	 * @return
	 */
	public String getString(String key) {
		String newKey = getFullKey(key);
		return _getString(newKey);
	}
	/**
	 * 获取字符型缓存,不补齐key前缀项目
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	public String getString(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		return _getString(newKey);
	}
	/**
	 *  获取字符型缓存
	 * @param key redis缓存key
	 * @return
	 */
	private String _getString(String key) {
		return (String) redisTemplate.opsForValue().get(key);
	}
	
	
	/**
	 * 设置对象型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * 
	 * @param key redis缓存key
	 * @param value
	 */
	public void setObject(String key, Object value) {
		String newKey = getFullKey(key);
		_setObject(newKey,value,defaultExpireTime);
	}
	
	/**
	 * 设置对象型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 
	 * @param key redis缓存key
	 * @param value
	 * @param expireTime 缓存有效期(秒)
	 */
	public void setObject(String key, Object value, long expireTime) {
		String newKey = getFullKey(key);
		_setObject(newKey,value,expireTime);
	}
	
	/**
	 * 设置对象型缓存,不补齐key前缀项目
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * 
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @param value
	 */
	public void setObject(String prefixKey, String key, Object value) {
		String newKey = getCustomKey(prefixKey, key);
		_setObject(newKey,value,defaultExpireTime);
	}
	
	/**
	 * 设置对象型缓存,不补齐key前缀项目
	 * 
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @param value
	 * @param expireTime 缓存有效期(秒)
	 */
	public void setObject(String prefixKey, String key, Object value, long expireTime) {
		String newKey = getCustomKey(prefixKey, key);
		_setObject(newKey, value,expireTime);
	}

	/**
	 * 设置对象型缓存
	 * 
	 * @param key redis缓存key
	 * @param value
	 * @param expireTime 缓存有效期(秒)
	 */
	@SuppressWarnings("unchecked")
	private void _setObject(String key, Object value,  long expireTime) {
		redisTemplate.opsForValue().set(key, value,expireTime, TimeUnit.SECONDS);
	}
	
	
	/**
	 * 获取对象型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 
	 * @param key redis缓存key
	 * @return
	 */
	public Object getObject(String key) {
		String newKey = getFullKey(key);
		return _getObject(newKey);
	}
	/**
	 * 获取对象型缓存,不补齐key前缀项目
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	public Object getObject(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		return _getObject(newKey);
	}
	/**
	 *  获取对象型缓存
	 * @param key redis缓存key
	 * @return
	 */
	private Object _getObject(String key) {
		return redisTemplate.opsForValue().get(key);
	}
	
	
	/**
	 * 删除缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 
	 * @param key redis缓存key
	 */
	public void deleteByKey(String key) {
		String newKey = getFullKey(key);
		_deleteByKey(newKey);
	}
	
	/**
	 * 删除缓存,不补齐key前缀项目
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	public void deleteByKey(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		_deleteByKey(newKey);
	}
	
	/**
	 * 删除缓存
	 * @param key
	 */
	@SuppressWarnings("unchecked")
	private void _deleteByKey(String key) {
		redisTemplate.delete(key);
	}
	/**
	 * 重新设置redis缓存有效期,自动补齐key前缀项目: "company","system”,"project","module"
	 * 
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 */
	public void setExpireTime(String key, long expireTime) {
		String newKey = getFullKey(key);
		_setExpireTime(newKey,expireTime);
	}
	
	/**
	 * 重新设置redis缓存有效期,不补齐key前缀项目
	 * 
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 */
	public void setExpireTime(String prefixKey, String key, long expireTime) {
		String newKey = getCustomKey(prefixKey, key);
		_setExpireTime(newKey,expireTime);
	}
	
	/**
	 *  重新设置redis缓存有效期,自动补齐key前缀项目: "company","system”,"project","module"
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 */
	@SuppressWarnings("unchecked")
	private void _setExpireTime(String key, long expireTime) {
		redisTemplate.expire(key, expireTime, TimeUnit.SECONDS);
	}
	

	/**
	 *  操作Value值类型工具,自动补齐key前缀项目: "company","system”,"project","module"
	 *  默认有效期为长期，需根据业务自行设置
	 * @param key redis缓存key
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundValueOperations boundValueOps(String key) {
		String newKey = getFullKey(key);
		BoundValueOperations<String,Object> opsForValue= redisTemplate.boundValueOps(newKey);
		return opsForValue;
	}

	
	/**
	 * 操作Value值类型工具,不补齐key前缀项目
	 * 默认有效期为长期，需根据业务自行设置
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundValueOperations<String, Object> boundValueOps(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		BoundValueOperations opsForValue = redisTemplate.boundValueOps(newKey);
		return opsForValue;
	}
	
	/**
	 *  操作Hash值类型工具,自动补齐key前缀项目: "company","system”,"project","module"
	 *  默认有效期为长期，需根据业务自行设置
	 * @param key redis缓存key
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundHashOperations boundHashOps(String key) {
		String newKey = getFullKey(key);
		BoundHashOperations<String,String,Object> opsForHash = redisTemplate.boundHashOps(newKey);
		return opsForHash;
	}

	
	/**
	 * 操作Hash值类型工具,不补齐key前缀项目
	 * 默认有效期为长期，需根据业务自行设置
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundHashOperations<String,String, Object> boundHashOps(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		BoundHashOperations opsForHash = redisTemplate.boundHashOps(newKey);
		return opsForHash;
	}
	
	/**
	 * 设置Hash型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param key
	 * @param map
	 */
	@SuppressWarnings("rawtypes")
	public void putAllHash(String key, Map map) {
		putAllHash(key, map,defaultExpireTime);
	}
	
	/**
	 * 设置Hash型缓存,自动补齐key前缀项目: "company","system”,"project","module" 
	 * @param key redis缓存key
	 * @param map
	 * @param expireTime 缓存有效期(秒)
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void putAllHash(String key, Map map, long expireTime) {
		BoundHashOperations opsForHash = boundHashOps(key);
		opsForHash.putAll(map);
		opsForHash.expire(expireTime, TimeUnit.SECONDS);
	}
	
	/**
	 * 设置Hash型缓存,,不补齐key前缀项目
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param prefixkey redis缓存key前缀
	 * @param key
	 * @param map
	 */
	@SuppressWarnings("rawtypes")
	public void putAllHash(String prefixkey, String key, Map map) {
		putAllHash(prefixkey,key, map,defaultExpireTime);
	}
	
	/**
	 * 设置Hash型缓存,,不补齐key前缀项目
	 * @param prefixkey redis缓存key前缀
	 * @param key redis缓存key
	 * @param map
	 * @param expireTime 缓存有效期(秒)
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void putAllHash(String prefixkey, String key, Map map, long expireTime) {
		BoundHashOperations opsForHash = boundHashOps(prefixkey,key);
		opsForHash.putAll(map);
		opsForHash.expire(expireTime, TimeUnit.SECONDS);
	}
	

	/**
	 *  操作List值类型工具,自动补齐key前缀项目: "company","system”,"project","module"
	 *  默认有效期为长期，需根据业务自行设置
	 * @param key redis缓存key
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundListOperations boundListOps(String key) {
		String newKey = getFullKey(key);
		BoundListOperations opsForList = redisTemplate.boundListOps(newKey);
		return opsForList;
	}
	/**
	 * 操作List值类型工具,不补齐key前缀项目
	 * 默认有效期为长期，需根据业务自行设置
	 * 
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundListOperations<String, Object> boundListOps(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		BoundListOperations opsForList = redisTemplate.boundListOps(newKey);
		return opsForList;
	}
	
	/**
	 * 设置Hash型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param key
	 * @param values
	 * 
	 * @return
	 */
	public Long putAllList(String key, Object... values) {
		return pushAllList(key, defaultExpireTime,values);
	}
	
	/**
	 * 设置List型缓存,自动补齐key前缀项目: "company","system”,"project","module" 
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 * @param values
	 * 
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Long pushAllList(String key, long expireTime, Object... values) {
		BoundListOperations opsForList = boundListOps(key);
		Long l = opsForList.leftPushAll(values);
		opsForList.expire(expireTime, TimeUnit.SECONDS);
		return l;
	}
	
	/**
	 * 设置list型缓存,,不补齐key前缀项目
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param prefixkey redis缓存key前缀
	 * @param key
	 * @param values
	 * 
	 * @return
	 */
	
	public Long pushAllList(String prefixkey, String key, Object... values) {
		return pushAllList(prefixkey,key, defaultExpireTime,values);
	}
	
	/**
	 * 设置list型缓存,,不补齐key前缀项目
	 * @param prefixkey redis缓存key前缀
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 * @param values
	 * 
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Long pushAllList(String prefixkey, String key, long expireTime, Object... values) {
		BoundListOperations opsForList = boundListOps(prefixkey,key);
		Long l = opsForList.leftPushAll(values);
		opsForList.expire(expireTime, TimeUnit.SECONDS);
		return l;
	}
	
	

	/**
	 * 操作Set值类型工具,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认有效期为长期，需根据业务自行设置
	 * @param key redis缓存key
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundSetOperations boundSetOps(String key) {
		String newKey = getFullKey(key);
		BoundSetOperations opsForSet = redisTemplate.boundSetOps(newKey);
		return opsForSet;
	}

	/**
	 * 操作Set值类型工具,不补齐key前缀项目
	 * 默认有效期为长期，需根据业务自行设置
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundSetOperations<String, Object> boundSetOps(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		BoundSetOperations opsForSet = redisTemplate.boundSetOps(newKey);
		return opsForSet;
	}

	/**
	 * 设置set型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param key redis缓存key
	 * @param values
	 */
	public Long addSet(String key, Object...values) {
		return addSet(key, defaultExpireTime, values);
	}
	/**
	 * 设置set型缓存,,不补齐key前缀项目
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param key redis缓存key
	 * @param values
	 */
	public Long addSet(String prefixKey, String key, Object... values) {
		return addSet(prefixKey, key, defaultExpireTime, values);
		
	}
	
	/**
	 * 设置set型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * @param prefixkey redis缓存key前缀
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 * @param values
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Long addSet(String key, long expireTime, Object...values) {
		BoundSetOperations opsForSet = boundSetOps(key);
		Long l = opsForSet.add(values);
		opsForSet.expire(expireTime, TimeUnit.SECONDS);
		return l;
	}
	
	
	/**
	 * 设置set型缓存,不补齐key前缀项目
	 * @param prefixkey redis缓存key前缀
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 * @param values
	 */
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Long addSet(String prefixKey, String key, long expireTime, Object... values) {
		BoundSetOperations opsForSet = boundSetOps(prefixKey,key);
		Long l = opsForSet.add(values);
		opsForSet.expire(expireTime, TimeUnit.SECONDS);
		return l;
	}
	
	/**
	 * 操作ZSet值类型工具,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认有效期为长期，需根据业务自行设置
	 * @param key redis缓存key
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundZSetOperations boundZSetOps(String key) {
		String newKey = getFullKey(key);
		BoundZSetOperations opsForZSet = redisTemplate.boundZSetOps(newKey);
		return opsForZSet;
	}
	
	/**
	 * 操作ZSet值类型工具,不补齐key前缀项目
	 * @param prefixKey redis缓存key前缀
	 * @param key redis缓存key
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public BoundZSetOperations<String, Object> boundZSetOps(String prefixKey, String key) {
		String newKey = getCustomKey(prefixKey, key);
		BoundZSetOperations opsForZSet = redisTemplate.boundZSetOps(newKey);
		return opsForZSet;
	}
	
	
	/**
	 * 设置zset型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param key redis缓存key
	 * @param setTuples
	 */
	public Long addZSet(String key, Set<TypedTuple<Object>> setTuples) {
		return addZSet(key, defaultExpireTime, setTuples);
	}
	/**
	 * 设置zset型缓存,,不补齐key前缀项目
	 * 默认缓存有效期为配置项{peak.redis.defaultExpireTime}
	 * @param key redis缓存key
	 * @param setTuples
	 */
	public Long addZSet(String prefixKey, String key, Set<TypedTuple<Object>> setTuples) {
		return addZSet(prefixKey, key, defaultExpireTime, setTuples);
		
	}
	
	/**
	 * 设置zset型缓存,自动补齐key前缀项目: "company","system”,"project","module"
	 * @param prefixkey redis缓存key前缀
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 * @param setTuples
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Long addZSet(String key, long expireTime, Set<TypedTuple<Object>> setTuples) {
		BoundZSetOperations opsForZSet = boundZSetOps(key);
		Long l = opsForZSet.add(setTuples);
		opsForZSet.expire(expireTime, TimeUnit.SECONDS);
		return l;
	}
	
	
	/**
	 * 设置zset型缓存,不补齐key前缀项目
	 * @param prefixkey redis缓存key前缀
	 * @param key redis缓存key
	 * @param expireTime 缓存有效期(秒)
	 * @param setTuples
	 */
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Long addZSet(String prefixKey, String key, long expireTime, Set<TypedTuple<Object>> setTuples) {
		BoundZSetOperations opsForZSet = boundZSetOps(prefixKey,key);
		Long l = opsForZSet.add(setTuples);
		opsForZSet.expire(expireTime, TimeUnit.SECONDS);
		return l;
	}
	
	@SuppressWarnings("rawtypes")
	public RedisTemplate getRedisTemplate() {
		return redisTemplate;
	}	
	
}

